package router

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"queue-gateway/common"
	"time"
)

func ApiRegister(g *gin.Engine) {

	//对于没有的路由，返回404，默认返回: 200
	g.NoRoute(func(context *gin.Context) {
		context.Status(http.StatusNotFound)
	})

	g.GET("/healthz", HealthCheck)
	g.GET("/time", SystemTime)

	group := g.Group("/balance")
	//group.Use(middleware.SignCheck, middleware.RateLimitMid)
	group.Use(common.ErrHandler())
	{
		group.POST("/:upstream/*path", ServerHandler)
	}

}

func SystemTime(ctx *gin.Context) {
	ctx.JSON(200, time.Now().Unix())
}

func HealthCheck(ctx *gin.Context) {
	ctx.JSON(200, map[string]interface{}{"errno": 0, "errmsg": "success"})
}
